package alo.p5.work;


import java.util.LinkedList;
import java.util.Queue;
//用两个队列实现栈
public class StackWithTwoQueues {
    Queue queue1;
    Queue queue2;
    public  StackWithTwoQueues(){
        queue1=new LinkedList();
        queue2=new LinkedList();
    }
    public boolean isEmpty(){
        if (queue1.isEmpty()&&queue2.isEmpty())
            return true;
        return false;
    }
    public void push(int data){
        if (queue1.isEmpty()){
            queue2.offer(data);
        }else queue1.offer(data);
    }
    public int pop(){
        int i = 0,size;
        if (queue2.isEmpty()){
            size=queue1.size();
            while (i<size-1){
                queue2.offer(queue1.poll());
                i++;
            }
            return (int) queue1.poll();
        }else {
            size=queue2.size();
            while (i<size-1){
                queue1.offer(queue2.poll());
                i++;
            }
            return (int) queue2.poll();
        }
    }
}
